package com.qf.controller;

import com.qf.pojo.Sys_city;
import com.qf.pojo.Sys_user;
import com.qf.service.Sys_cityService;
import com.qf.service.Sys_userService;
import com.qf.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

//City控制层
@RestController
public class sys_cityController {
    @Autowired
    Sys_cityService sysCityService;
    @Autowired
    Sys_userService sysUserService;
    //根据pid查询城市信息
    @RequestMapping(value = "/getCity",method = RequestMethod.GET)
    public BaseResult getCity(Integer pid){
        Sys_city city=sysCityService.select(pid);
        BaseResult baseResult=new BaseResult();
        baseResult.setCode(9760);
        baseResult.setMessage(null);
        baseResult.setData(city);
        baseResult.setCount(0L);
        return baseResult;
    }
    //根据id查询城市信息
    //getid取车地址
    //backid换车地址
    @RequestMapping(value = "/getCities",method = RequestMethod.GET)
    public BaseResult getCities(@RequestParam("getid")Integer getid,@RequestParam("backid")Integer backid,@RequestParam("uid")Integer uid){
        List cities=new ArrayList<>();
        Sys_city getCity=sysCityService.select(getid);
        Sys_city backCity=sysCityService.select(backid);
        Sys_city getCityByPid=sysCityService.select(getCity.getPid());
        Sys_city backCityByPid=sysCityService.select(backCity.getPid());
        Sys_user user=sysUserService.findById(uid);
        cities.add(getCity);
        cities.add(backCity);
        cities.add(getCityByPid);
        cities.add(backCityByPid);
        cities.add(user);
        BaseResult baseResult=new BaseResult();
        baseResult.setCode(9760);
        baseResult.setMessage(null);
        baseResult.setData(cities);
        baseResult.setCount(0l);
        return baseResult;
    }
}
